package com.app.push.dao.impl;

import com.app.push.dao.UPushDao;
import com.app.push.model.PushUser;
import com.app.sysmodule.dao.impl.BaseDaoImpl;
import com.app.sysmodule.exception.DBException;
import org.hibernate.Query;

import java.util.List;

/**
 * Created by song on 2018/1/12.
 */
public class UPushDaoImpl extends BaseDaoImpl<PushUser> implements UPushDao {
    public PushUser findUserByDeviceId(String deviceId) throws DBException{
        try{
            String hql = " from PushUser where deviceId=(:deviceId) and isDelete=0 ";
            Query query = this.getSession().createQuery(hql).setParameter("deviceId",deviceId);
            List<PushUser> list= (List<PushUser>)query.list();
            if(null != list && list.size()>0){
                return (PushUser)list.get(0);
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new DBException(e.getMessage());
        }
        return null;
    }

    public List<String> getDeviceToken(List<String> users,String type) {
        String sql = "SELECT device_token from a_push_user where user_id in() and type=(:type)";
        return this.getSession().createSQLQuery(sql).setParameterList("list",users).setParameter("type",type).list();
    }
}
